home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok22.lha
/
Cube
/
SolidCUBE.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
9KB
|
364 lines
(*******************************************************************************
:Program. SolidCUBE.MOD
:Author. Carsten Wartmann / Mathematics by André Theiler
:Address. Wutzkyallee 83, D-1000 Berlin 47
:Phone. 030/6614776
:Version. 1.5
:Date. 3/89
:Copyright. PD
:Language. Modula-2
:Compiler. M2Amiga V3.2d
:Contents. Echtzeitanimation eines Würfels
*******************************************************************************)
(* More Info : See DOC-File... *)
MODULE SolidCUBE ;
FROM SYSTEM IMPORT BITSET,ADR,FFP,ADDRESS ;
FROM Intuition IMPORT NewScreen,ScreenPtr,OpenScreen,CloseScreen,customScreen,
NewWindow,WindowPtr,ScreenToFront,
IDCMPFlags,IDCMPFlagSet,WindowFlags,WindowFlagSet,
OpenWindow,CloseWindow ;
FROM Graphics IMPORT ViewModes,ViewModeSet,Move,Draw,SetAPen,jam1,
RastPortPtr,ClearScreen,SetRGB4,TmpRas,AreaInfo,
InitArea,InitTmpRas,AreaEnd,AreaMove,AreaDraw,
FreeRaster,AllocRaster,WaitBOVP,ViewPortPtr ;
FROM MathLibFFP IMPORT sin,cos,pi ;
CONST PUNKTE = 8 ;
PproFLAECHE = 4 ;
FLAECHEN = 6 ;
BEOX = 0.0 ; (* Standort des Beobachters *)
BEOY = -400.0 ;
BEOZ = 0.0 ;
VAR screen : NewScreen ;
screenptr : ARRAY [0..1] OF ScreenPtr ;
window : NewWindow ;
windowptr : ARRAY [0..1] OF WindowPtr ;
drawRP : ARRAY [0..1] OF RastPortPtr ;
viewP : ARRAY [0..1] OF ViewPortPtr ;
cia[0BFE000H] : BITSET ;
Joy1[0DFF00CH] : BITSET ;
buffer : ARRAY [0..1],[0..255] OF INTEGER ;
tmp : ARRAY [0..1] OF TmpRas ;
areainfo : ARRAY [0..1] OF AreaInfo ;
mem : ARRAY [0..1] OF ADDRESS ;
scr1,scr0,scra,i : INTEGER ;
x,y,z : ARRAY [0..PUNKTE] OF FFP ;
flaeche : ARRAY [0..FLAECHEN*PproFLAECHE] OF INTEGER ;
beox,beoy,beoz : FFP ;
drehz,drehy : FFP ;
PROCEDURE Rechts() : BOOLEAN ; (* Routinen zur Joystickabfrage *)
BEGIN
RETURN (1 IN Joy1) ;
END Rechts ;
PROCEDURE Links() : BOOLEAN ;
BEGIN
RETURN (9 IN Joy1) ;
END Links ;
PROCEDURE XOR(a,b : BOOLEAN) : BOOLEAN ;
BEGIN
RETURN ((a OR b) AND NOT (a AND b)) ;
END XOR ;
PROCEDURE Unten() : BOOLEAN ;
BEGIN
RETURN XOR(Rechts(),(0 IN Joy1)) ;
END Unten ;
PROCEDURE Oben() : BOOLEAN ;
BEGIN
RETURN XOR(Links(),(8 IN Joy1)) ;
END Oben ;
PROCEDURE RotY(wi : FFP) ; (* Drehung um die Y-Achse*)
VAR i : INTEGER ;
xx,zz : FFP ;
BEGIN
FOR i := 0 TO PUNKTE-1 DO
xx := x[i] ;
zz := z[i] ;
x[i] := xx * cos(wi) + zz * sin(wi) ;
z[i] := zz * cos(wi) - xx * sin(wi) ;
END (*FOR*) ;
END RotY ;
PROCEDURE RotZ(wi : FFP) ; (* Drehung um die Z-Achse *)
VAR i : INTEGER ;
xx,yy : FFP ;
BEGIN
FOR i := 0 TO PUNKTE-1 DO
xx := x[i] ;
yy := y[i] ;
x[i] := xx * cos(wi) - yy * sin(wi) ;
y[i] := xx * sin(wi) + yy * cos(wi) ;
END (*FOR*) ;
END RotZ ;
PROCEDURE Zeichne ;
VAR i,j,l,ii : INTEGER ;
xbild,ybild : INTEGER ;
fehler : LONGINT ;
vx,vy,vz,wx,wy,wz,px,py,
pz,sx,sy,sz,q : FFP ;
BEGIN
FOR l := 0 TO FLAECHEN-1 DO
ii := l * PproFLAECHE ;
vx := x[flaeche[ii+1]] - x[flaeche[ii]] ;
vy := y[flaeche[ii+1]] - y[flaeche[ii]] ;
vz := z[flaeche[ii+1]] - z[flaeche[ii]] ;
wx := x[flaeche[ii+2]] - x[flaeche[ii]] ;
wy := y[flaeche[ii+2]] - y[flaeche[ii]] ;
wz := z[flaeche[ii+2]] - z[flaeche[ii]] ;
px := vy*wz - vz*wy ;
py := vz*wx - vx*wz ;
pz := vx*wy - vy*wx ;
sx := x[flaeche[ii]] - beox ;
sy := y[flaeche[ii]] - beoy ;
sz := z[flaeche[ii]] - beoz ;
q := sx*px + sy*py + sz*pz ;
IF NOT(q<0.0) THEN
FOR j := 0 TO PproFLAECHE-1 DO
i := flaeche[l * PproFLAECHE + j] ;
xbild := 160 + TRUNC(beox + beoy / (beoy - y[i]) * (x[i] - beox)) ;
ybild := 120 + TRUNC(beoz + beoy / (beoy - y[i]) * (z[i] - beoz)) ;
IF (j<1) THEN
fehler := AreaMove(drawRP[scr0],xbild,ybild) ;
ELSE
fehler := AreaDraw(drawRP[scr0],xbild,ybild) ;
END (*IF*) ;
END (*FOR j*) ;
SetAPen(drawRP[scr0],l+1) ;
fehler := AreaEnd(drawRP[scr0]) ;
END (*IF q>0.0*) ;
END (*FOR l*) ;
END Zeichne ;
PROCEDURE Rotate ;
VAR i : INTEGER ;
BEGIN
x[0] := 30.0 ; (* Punktkoordinaten *)
y[0] := 30.0 ;
z[0] := 30.0 ;
x[1] := 30.0 ;
y[1] := 30.0 ;
z[1] := -30.0 ;
x[2] := 30.0 ;
y[2] := -30.0 ;
z[2] := -30.0 ;
x[3] := 30.0 ;
y[3] := -30.0 ;
z[3] := 30.0 ;
x[4] := -30.0 ;
y[4] := 30.0 ;
z[4] := 30.0 ;
x[5] := -30.0 ;
y[5] := 30.0 ;
z[5] := -30.0 ;
x[6] := -30.0 ;
y[6] := -30.0 ;
z[6] := -30.0 ;
x[7] := -30.0 ;
y[7] := -30.0 ;
z[7] := 30.0 ;
flaeche[0] := 0 ; (* Flaechenzuordnung der Punkte *)
flaeche[1] := 1 ;
flaeche[2] := 2 ;
flaeche[3] := 3 ;
flaeche[4] := 4 ;
flaeche[5] := 7 ;
flaeche[6] := 6 ;
flaeche[7] := 5 ;
flaeche[8] := 0 ;
flaeche[9] := 4 ;
flaeche[10] := 5 ;
flaeche[11] := 1 ;
flaeche[12] := 3 ;
flaeche[13] := 2 ;
flaeche[14] := 6 ;
flaeche[15] := 7 ;
flaeche[16] := 1 ;
flaeche[17] := 5 ;
flaeche[18] := 6 ;
flaeche[19] := 2 ;
flaeche[20] := 0 ;
flaeche[21] := 3 ;
flaeche[22] := 7 ;
flaeche[23] := 4 ;
drehz := 10.0 * pi / 180.0 ; (* Winkelgeschwindigkeit *)
drehy := 10.0 * pi / 180.0 ; (* der Drehung *)
scr0 := 0 ;
scr1 := 1 ;
WHILE (6 IN cia) DO (* Solange bis Mausknopf *)
Zeichne ;
WaitBOVP(viewP[scr1]) ;
ScreenToFront(screenptr[scr0]) ;
WHILE (NOT(Rechts() OR Links() OR Unten() OR Oben()
OR (NOT(6 IN cia)))) DO
END (*WHILE*) ;
IF (7 IN cia) THEN
IF Rechts() THEN
RotY(-drehz) ;
END ;
IF Links() THEN
RotY(drehz) ;
END ;
IF Oben() THEN
RotZ(drehy) ;
END ;
IF Unten() THEN
RotZ(-drehy) ;
END (*IF*) ;
END (*IF*) ;
IF (Unten() AND (NOT(7 IN cia))) THEN
beoy := beoy + 10.0 ; (* Beobachter entfernen *)
IF (beoy > (-60.0)) THEN
beoy := -60.0 ;
END (*IF*) ;
ELSIF (Oben() AND (NOT(7 IN cia))) THEN
beoy := beoy - 10.0 ; (* Beobachter annähern *)
IF (beoy < (-1800.0)) THEN
beoy := -1800.0 ;
END (*IF*) ;
END (*IF*) ;
scra := scr0 ;
scr0 := scr1 ;
scr1 := scra ;
Move(drawRP[scr0],0,0) ;
ClearScreen(drawRP[scr0]) ;
END (*WHILE*) ;
END Rotate ;
BEGIN (* Hauptprogramm Screens *)
FOR i := 0 TO 1 DO
WITH screen DO (* Stark verkuerzt !!! *)
width := 320 ; (* Vorsicht : Bei Aenderungen *)
height := 256 ; (* am besten alles auffuehren *)
depth := 3 ;
END (*WITH*) ;
screenptr[i] := OpenScreen(screen) ;
WITH window DO
width := 320 ;
height := 255 ;
screen := screenptr[i] ;
END (*WITH*) ;
windowptr[i] := OpenWindow(window) ;
drawRP[i] := windowptr[i]^.rPort ;
viewP[i] := ADR(screenptr[i]^.viewPort) ;
mem[i] := AllocRaster(320,256) ;
InitArea(areainfo[i],ADR(buffer[i,0]),8) ;
InitTmpRas(tmp[i],mem[i],20) ;
windowptr[i]^.rPort^.tmpRas := ADR(tmp[i]) ;
windowptr[i]^.rPort^.areaInfo := ADR(areainfo[i]) ;
END (*FOR i*) ;
beox := BEOX ;
beoy := BEOY ;
beoz := BEOZ ;
Rotate ;
FOR i := 0 TO 1 DO
CloseWindow(windowptr[i]) ;
CloseScreen(screenptr[i]) ;
FreeRaster(mem[i],320,256) ;
END (*FOR i*) ;
END SolidCUBE .